use std::mem::MaybeUninit;

use sqlx::SqlitePool;

use crate::{config::DB_PATH, error::AppErr};



pub mod hex;
pub mod pro;

static mut POOL: MaybeUninit<SqlitePool> = MaybeUninit::uninit();


pub async fn init() -> Result<(), AppErr> {

    let url = format!("sqlite://{}?mode=rwc", DB_PATH);
    let pool = SqlitePool::connect(&url).await?;
    unsafe { POOL.write(pool); }
    pro::init().await?;
    hex::init().await?;
    Ok(())
}

pub fn get_pool() -> &'static SqlitePool {
    unsafe { POOL.assume_init_ref() }
}

